//
//  FJRecordViewController.swift
//  FruitJuice
//
//  Created by Rui on 2024/1/7.
//

import UIKit

class FJRecordViewController: FJBaseViewController {

    private let backButton          = c_make_ex(UIButton.self)
        .image("FJ_Profile_back").end()
    private let recordButton        = c_make_ex(UIButton.self)
        .bgColor("#FF9133").color(.white).text("Record")
        .corner(18.5).font(16.font_medium).end()
    private let titleLabel          = c_make_ex(UILabel.self)
        .text("Every Drink You Make").color(.black)
        .font(23.font_wide).end()
    private lazy var tableView: UITableView = {
        let tableView = UITableView()
        tableView.backgroundColor = .clear
        tableView.tableFooterView = UIView(frame: .zero)
        tableView.separatorStyle = .none
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(FJRecordCell.self)
        tableView.register(FJRecordTitleHeaderView.self, forHeaderFooterViewReuseIdentifier: FJRecordTitleHeaderView.description())
        return tableView
    }()
    
    private var dataSource:[InfoUtil.room] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()

        loadData()
        
        view.subviews{
//            tableView
            backButton
            recordButton
            titleLabel
        }
        
        backButton.top(.statusHeight + 7).leading(15).size(30)
        recordButton.trailing(15).height(38).width(85)
        backButton.CenterY == recordButton.CenterY
        titleLabel.leading(15)
        titleLabel.Top == recordButton.Bottom + 13
        
        backButton.addTarget(self, action: #selector(clickBackButton), for: .touchUpInside)
        recordButton.addTarget(self, action: #selector(clickRecordButton), for: .touchUpInside)
    }
    
    private func loadData(){
        
        RT.getRoomList { list in
            self.dataSource.removeAll()
            for item in list{
                if item?.houseName == "___*FruitJuice" && item?.createUserId == USEINFOMODEL.id {
                    self.dataSource.append(item!)
                }
            }

        }
    }
    
    @objc private func clickBackButton(){
        self.navigationController?.popViewController(animated: true)
    }
    @objc private func clickRecordButton(){
        self.navigationController?.pushViewController(FJPushViewController(), animated: true)
    }
}

extension FJRecordViewController: UITableViewDelegate,UITableViewDataSource{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 10
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.cell(FJRecordCell.self, indexPath: indexPath)
//        cell.model = commentList[indexPath.row - 1]
//        cell.blackClosure = { [weak self] userId in
//            let reportV = FJReportView()
//            reportV.otherId = userId
//            self?.saAnimate.animation(show: reportV)
//        }
        return cell
    }
    
//    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
//
//        let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: FJRecordTitleHeaderView.description()) as! FJRecordTitleHeaderView
//        let model = dataSource[section]
//        if let titleStr = model.info4, titleStr.count > 0 {
//            header.titleStr = titleStr
//        }else{
//            let timeStamp = Int(model.createTime ?? "0")
//            header.titleStr = timeStamp!.toTimeStr()
//        }
//        return header
//    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        
        return 45
    }

}
